#ifndef _MISSION_MODEL_H_
#define _MISSION_MODEL_H_


#include "Common.h"
#include "Resource.h"
#include "String.h"
#include "SharedPtr.h"
#include "ResourceManager.h"
#include "tinyxml/tinyxml.h"
#include "XMLData.h"

class SERVER_DECL MissionModel : public Resource
{
protected:
	uint32		m_serial;
	uint32		m_group_id;    //login server group id

        void prepareImpl(void);
        /** Destroys data cached by prepareImpl.
         */
        void unprepareImpl(void);
        /// @copydoc Resource::loadImpl
        bool loadImpl(void);
        /// @copydoc Resource::postLoadImpl
        void postLoadImpl(void);
        /// @copydoc Resource::unloadImpl
        void unloadImpl(void);
        /// @copydoc Resource::calculateSize
        size_t calculateSize(void) const;

	void initialize(void);

public:
	MissionModel(ResourceManager* creator, const String& name, ResourceHandle handle,
            const String& group, bool isManual = false, ManualResourceLoader* loader = 0);
	~MissionModel(void);


	const uint32 & getSerial(void)		{	return m_serial;	}

	const uint32 & getGid(void)		{	return m_group_id;	}
	
	 //任务条件      
        XMLDataSet      require;
        //任务奖励      
        XMLDataSet      bounty;

	bool	LoadDB(void);
	bool	SaveDB(void);
	bool 	FetchDB(Field * fields);

private:
	/* base server_id and username connect db get uid
	 if resource loaded direct return uid */
};

    /** Specialisation of SharedPtr to allow SharedPtr to be assigned to ItemPtr 
    @note Has to be a subclass since we need operator=.
    We could templatise this instead of repeating per Resource subclass, 
    except to do so requires a form VC6 does not support i.e.
    ResourceSubclassPtr<T> : public SharedPtr<T>
    */
    class SERVER_DECL  MissionModelPtr : public SharedPtr<MissionModel>
    {
    public:
        MissionModelPtr() : SharedPtr<MissionModel>() {}
        explicit MissionModelPtr(MissionModel* rep) : SharedPtr<MissionModel>(rep) {}
        MissionModelPtr(const MissionModelPtr& r) : SharedPtr<MissionModel>(r) {}
        MissionModelPtr(const ResourcePtr& r);
        /// Operator used to convert a ResourcePtr to a MeshPtr
        MissionModelPtr& operator=(const ResourcePtr& r);
    protected:
        /// Override destroy since we need to delete Mesh after fully defined
        void destroy(void);
    };
	

#endif
